package com.palmind.tree;

import com.palmind.parser.tags.AbstractTag;
import com.palmind.util.ArrayList;

/**
 * The class <code>TreeNode</code> is the object existing on a node tree.
 * 
 * @author Jarod Yv
 */
public class TreeNode {
	private TreeNode parent = null;
	private ArrayList children = null;
	private AbstractTag body = null;

	public AbstractTag getBody() {
		return body;
	}

	public void setBody(AbstractTag body) {
		this.body = body;
	}

	public TreeNode getParent() {
		return parent;
	}

	public void setParent(TreeNode parent) {
		this.parent = parent;
	}

	public TreeNode getChildrenByIndex(int index) {
		if (children == null || index >= children.size())
			return null;
		return (TreeNode) this.children.get(index);
	}

	public ArrayList getChildren() {
		return children;
	}

	public int getChildrenNum() {
		return children == null ? 0 : children.size();
	}

	public void addChildren(TreeNode child) {
		if (child == null)
			return;
		child.setParent(this);
		if (this.children == null)
			this.children = new ArrayList(10);
		this.children.add(child);
	}
}
